
  <!-- content start -->
  <div class="admin-content">
    <div class="admin-content-body">
     
      <hr/>

      <div class="am-g">
        <div class="am-u-sm-12 am-u-md-4 am-u-md-push-8">
          

        </div>

        <div class="am-u-sm-12 am-u-md-8 am-u-md-pull-4">
          <form action="{:Url('admin/addshop/tianjia')}" class="am-form am-form-horizontal" enctype="multipart/form-data"	method="post">
            <div class="am-form-group">
              <label for="user-name" class="am-u-sm-3 am-form-label">标题 </label>
              <div class="am-u-sm-9">
                <input type="text" name="title" >
              </div>
            </div>

            <div class="am-form-group">
                <label for="user-name" class="am-u-sm-3 am-form-label">进货价格 </label>
                <div class="am-u-sm-9">
                  <input type="text" name="purchasePrice" >
                </div>
              </div>

              <div class="am-form-group">
                <label for="user-name" class="am-u-sm-3 am-form-label">市场价格 </label>
                <div class="am-u-sm-9">
                  <input type="text" name="marketPrice" >
                </div>
              </div>

              <div class="am-form-group">
                <label for="user-name" class="am-u-sm-3 am-form-label">本店售价 </label>
                <div class="am-u-sm-9">
                  <input type="text" name="shopPrice" >
                </div>
              </div>

              <div class="am-form-group">
                <label for="user-name" class="am-u-sm-3 am-form-label">销量 </label>
                <div class="am-u-sm-9">
                  <input type="text" name="salesNum" >
                </div>
              </div>

              <div class="am-form-group">
                <label for="user-name" class="am-u-sm-3 am-form-label">库存 </label>
                <div class="am-u-sm-9">
                  <input type="text" name="stockNum" >
                </div>
              </div>


              <div class="am-form-group">
                <label for="user-name" class="am-u-sm-3 am-form-label">分类 </label>
                <div class="am-u-sm-9">
                  <select  id="fenlei" style="width:150px;" onchange="dian(this)">
                    {volist name="res" id="vo"}
                    <option value="{$vo.id}">{$vo.name}</option>
                    {/volist}
                  </select>
                  <select name="classification" id="showup" style="width:150px;float:left;margin:-37px 0px 0px 155px;">
                   
                    </select>
                </div>
              </div>

            <div class="am-form-group">
              <label for="user-name" class="am-u-sm-3 am-form-label">缩略图</label>
              <div class="am-u-sm-9">
                <input type="file" name="img" onchange="upImg(this)" >
                <span id="img_show" ></span>
              </div>
            </div>
            

            <div class="am-form-group">
              <label for="user-name" class="am-u-sm-3 am-form-label">商品详情 </label>
              <div class="am-u-sm-9">
                <!-- 加载编辑器的容器 -->
                <textarea id="container" name="content" type="text/plain" style="width:800px;height:600px;">
                    
                </textarea>
                <!-- 配置文件 -->
                <script type="text/javascript" src="__STATIC__/UEditor/ueditor.config.js"></script>
                <!-- 编辑器源码文件 -->
                <script type="text/javascript" src="__STATIC__/UEditor/ueditor.all.js"></script>
                <!-- 实例化编辑器 -->
                <script type="text/javascript">
                    var ue = UE.getEditor('container');
                </script>
              </div>
            </div>

            <div class="am-form-group">
              <div class="am-u-sm-9 am-u-sm-push-3">
                <button type="submit" class="am-btn am-btn-primary" onclick="publish">添加</button>
              </div>
            </div>
          </form>
        </div>
        
      </div>
    </div>

    <footer class="admin-content-footer">
      <hr>
      <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
    </footer>

  </div>
  <script >
      function upImg(obj)
          {
          if( obj.value == "" ) {
              return;
          }
          var formdata = new FormData(); 
          //<input type="file" name="img" />
          formdata.append("img" , $(obj)[0].files[0]);//获取文件法二
          $.ajax({
              type : 'post',
              url : "{:Url('admin/addshop/upload')}",
              data : formdata,
              cache : false,
              processData : false, // 不处理发送的数据，因为data值是Formdata对象，不需要对数据做处理
              contentType : false, // 不设置Content-type请求头
              success : function(ret){
                  var html='<span class="img_html">'
                      html+='<img src="'+ret+'" alt="" width="100px" height="100px">'
                      html+='<span onclick="delImg(this)" class="img_del">删除</span>'
                      html+='<input type="hidden" name="img[]" style="width:100px;" value="'+ret+'">'
                      html+='</span>'
                  $('#img_show').append(html);
              },
              error : function(){ }
          });

      }
      function delImg(obj){
          $(obj).parent().remove()
      }
      function publish(){
          $.ajax({
              url:"{:Url('admin/addshop/tianjia')}",
              data:{title:$('.title').html(),purchasePrice:$('.purchasePrice').html(),marketPrice:$('.marketPrice').html(),
              shopPrice:$('.shopPrice').html(),salesNum:$('.salesNum').html(),stockNum:$('.stockNum').html(),
              classification:$('.classification').html(),content:$('.content').html(),},
              dataType:'html',
              type:'post',
              success:function(data){
              }
                  
          })
      }
      function dian(obj){
          // alert ($(obj).val());
          $.ajax({
              url:"{:Url('admin/addshop/index')}",
              data:{fenlei:$(obj).val()},
              dataType:'json',
              type:'post',
              success:function(ret){
                // console.log(ret);
                // console.log(ret[0]);
                var html='';
                for(var i=0; i<ret.length ;i++){
                   html += "<option value="+ret[i].id+">"+ret[i].name+"</option>";
                  $('#showup').html(html);
                }
              }
             
          })
          

      }
  </script>
  <!-- content end -->
  
